var Promise = require('bluebird');
var mongoBase = require('../common/mongo-base');

function home(req, res, next) {

  var query = {};
  var fieldsBanner = {_id:1, artibodyTitle:1, photo:1, key:1};
  var fieldsPromotion = {_id:1, artibodyTitle:1, photo:1, ellipsis:1, key:1};
  var options = {sort:{date:1}, limit: 10};

  Promise.all([
    mongoBase.findData('home-banner', query, fieldsBanner, options),
    mongoBase.findData('home-promotion', query, fieldsPromotion, options)
  ])

  .then(function(results) {

    var resData = {
      isHome: true,
      searchType: 'news',
      banners: results[0],
      newsList: results[1]
    };
    res.render('home', resData);
  })

  .catch(function(err){
    console.log(err);
  });
}

exports.home = home;
